package com.lrm.service;

import com.lrm.dao.PicRepository;
import com.lrm.po.Pic;
import com.lrm.util.MyBeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @Author: 王金海
 * @Description:
 * @Date: Created by Administrator on 2018/7/17.
 * @Modified By:
 */
@Service
public class PicServiceImpl implements PicService {

    @Autowired
    private PicRepository picRepository;
    @Override
    public Page<Pic> listPic(Pageable pageable) {
        return picRepository.findAll(pageable);
    }

    @Override
    public Pic savePic(byte[] bytes, String filePath, String fileName) throws Exception {
        MyBeanUtils.uploadFile(bytes, filePath, fileName);
        Pic pic = new Pic();
        pic.setAddr(fileName);
        pic.setCreateTime(new Date());
        return picRepository.save(pic);
    }
}
